// pages/closeAccount/closeAccount.js
const httpUtils = require('../../utils/httpUtils.js');
const app = getApp()
Page({

  /**
   * 结算明细  页面的初始数据
   */
  data: {
    showSearchResult: false,
    page:1,
    lists:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData()
  },
  getData: function () {
    let that = this
    wx.showLoading({
      title: '正在加载',
      mask: true
    })
    httpUtils.settlement({
      access_token: app.globalData.$TOKEN,
      page: that.data.page,
      size: 20,
    }).then((res) => {
      wx.hideLoading()
      if (res.data.lists.length == 0) {
        that.setData({
          showSearchResult: false
        })
      } else {
        console.log("showSearchResult:" + that.data.showSearchResult);
        that.setData({
          showSearchResult: true
        })
      }
      if (that.data.page == 1) {
        that.data.lists = []
        that.data.lists.push(...res.data.lists);
      } else {
        that.data.lists.push(...res.data.lists);
      }
      that.setData({
        lists: that.data.lists,
        tobesettled: res.data.tobesettled,
        havesettled: res.data.havesettled
      });
      that.data.page = that.data.page + 1;

    });

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.showSearchResult) {
      this.getData();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})